package com.sky.mapper;

import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author moningxi
 */
@Mapper
public interface OrderDetailMapper {
    /**
     * 批量插入订单关联信息
     */
    void insertBatch(List<OrderDetail> orderDetails);

    /**
     * 更据订单id查询订单明细
     */
    @Select("select * from order_detail where order_id=#{id}")
    List<OrderDetail> listByOrderId(Long id);

    /**
     * 获取销量前十的菜品
     */
    @Select("SELECT `name`,SUM(od.number) num FROM orders o,order_detail od WHERE o.id=od.order_id and o.order_time>=#{beginTime} and o.order_time<=#{endTime} and o.status=#{status} GROUP BY `name`  ORDER BY num DESC LIMIT 10")
    List<Map<String, Object>> getTop10(LocalDateTime beginTime, LocalDateTime endTime, int status);
}
